﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DeJC.BLL.Managers;
using DeJC.DAL.Model;
using TheList.Helper;

namespace TheList.Controllers
{
    public class MyListController : Controller
    {
        //
        // GET: /MyList/

        public ActionResult Index()
        {
            IEnumerable<UserList> userLists = UserListManager.GetUserLists();
            return View(userLists);
        }

        public ActionResult Create()
        {
            ViewBag.CategoryID = new SelectList(GeneralMiscTypeManager.GetChildren(Utility.ParentCategoryId), "ID",
                                                "Description");
            return View();
        }

        [HttpPost]
        public ActionResult Create(UserList userList) {
            if(ModelState.IsValid)
            {
                userList.UserID = Utility.GetCurrentUserId;
                UserListManager.AddUserList(userList);

                return RedirectToAction("Index");
            }
            ViewBag.CategoryID=new SelectList(GeneralMiscTypeManager.GetChildren(Utility.ParentCategoryId), "ID",
                                                "Description",userList.CategoryID);
            return View();
        }

        public ActionResult Details(int id)
        {
            UserList userList = UserListManager.GetById(id);
            return View(userList);

        }
    }
}
